//
//  OrderDetailView.swift
//  vmes
//
//  Created by 志鹏 翟 on 2022/3/6.
//

import UIKit
import SnapKit
class OrderDetailView: UIView {
    
    let orderNoLb=UILabel()
    let desc1Lb=UILabel()
    let desc2Lb=UILabel()
    let statusLb=UILabel()
    
    let planStartLb=UILabel()
    let realStartLb=UILabel()
    let planStopLb=UILabel()
    let realStopLb=UILabel()
    let planStart=UILabel()
    let planStop=UILabel()
    let realStart=UILabel()
    let realStop=UILabel()
    
    override init(frame: CGRect) {
        super.init(frame:frame)
        initView()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        initView()
    }
    
    private func initView(){
        self.backgroundColor=UIColor.colorWithHex(hexStr: "#E3E5E7")
        self.layer.cornerRadius=10
        orderNoLb.text="orderNo"
        statusLb.text="生产中"
        
        planStartLb.text="计划开始"
        realStartLb.text="实际开始"
        planStopLb.text="计划结束"
        realStopLb.text="实际结束"
        
        planStart.font = .systemFont(ofSize: 14)
        planStop.font = .systemFont(ofSize: 14)
        realStart.font = .systemFont(ofSize: 14)
        realStop.font = .systemFont(ofSize: 14)
        [orderNoLb,statusLb,desc1Lb,desc2Lb,planStop,planStart,
         planStopLb,planStartLb,realStop,realStart,realStopLb,realStartLb].forEach {
            self.addSubview($0)
        }
        orderNoLb.snp.makeConstraints { make in
            make.top.left.equalToSuperview().offset(20)
        }
        desc1Lb.snp.makeConstraints { make in
            make.left.equalTo(orderNoLb.snp.left)
            make.top.equalTo(orderNoLb.snp.bottom).offset(10)
        }
        desc2Lb.snp.makeConstraints { make in
            make.left.equalTo(orderNoLb.snp.left)
            make.top.equalTo(desc1Lb.snp.bottom)
        }
        statusLb.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-15)
            make.top.equalTo(orderNoLb.snp.top)
        }
        let line=UIView()
        line.backgroundColor = UIColor.colorWithHex(hexStr: "#6F6F6F")
        self.addSubview(line)
        line.snp.makeConstraints { make in
            make.height.equalTo(0.5)
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.top.equalTo(desc2Lb.snp.bottom)
                .offset(15)
        }
        //计划
        planStartLb.snp.makeConstraints { make in
            make.top.equalTo(line.snp.bottom).offset(15)
            make.left.equalTo(orderNoLb.snp.left)
        }
        planStart.snp.makeConstraints { make in
            make.top.equalTo(planStartLb.snp.bottom).offset(10)
            make.left.equalTo(planStartLb.snp.left)
        }
        planStopLb.snp.makeConstraints { make in
            make.top.equalTo(planStart.snp.bottom).offset(40)
            make.left.equalTo(planStartLb.snp.left)
        }
        planStop.snp.makeConstraints { make in
            make.top.equalTo(planStopLb.snp.bottom).offset(10)
            make.left.equalTo(planStopLb.snp.left)
        }
        //实际
        realStartLb.snp.makeConstraints { make in
            make.top.equalTo(line.snp.bottom).offset(15)
            make.left.equalTo(self.snp.centerX).offset(10)
        }
        realStart.snp.makeConstraints { make in
            make.top.equalTo(realStartLb.snp.bottom).offset(10)
            make.left.equalTo(realStartLb.snp.left)
        }
        realStopLb.snp.makeConstraints { make in
            make.top.equalTo(realStart.snp.bottom).offset(40)
            make.left.equalTo(realStartLb.snp.left)
        }
        realStop.snp.makeConstraints { make in
            make.top.equalTo(realStopLb.snp.bottom).offset(10)
            make.left.equalTo(realStartLb.snp.left)
        }
    }
    
    public func initData(orderInfo:OrderItem?){
        orderNoLb.text=orderInfo?.workorderCode
        desc1Lb.text=orderInfo?.productCode ?? "暂无产品内容"
        desc2Lb.text=orderInfo?.productName ?? "暂无产品内容"
        if("0"==orderInfo?.statusFlag!){
            statusLb.text="待生产"
        }else if("1"==orderInfo?.statusFlag!){
            statusLb.text="当班开工"
        }else if("2"==orderInfo?.statusFlag!){
            statusLb.text="当班完工"
        }else if("3"==orderInfo?.statusFlag!){
            statusLb.text="已完成"
        }
        planStart.text=orderInfo?.planStartTime
        planStop.text=orderInfo?.planEndTime
        realStart.text=orderInfo?.actualStartTime
        realStop.text=orderInfo?.actualEndTime
    }
}
